<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layuiAdmin 后台管理员</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC__/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/layuiadmin/style/admin.css" media="all">
    <style>

        .layui-textarea{ min-height: 190px;}

        .tishi li{text-indent: 20px;}
    </style>
</head>
<body>
    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">搜索域名</label>
            <div class="layui-input-block">
              <input type="text" name="domain" placeholder="如：wxcopy.trj.com" autocomplete="off" class="layui-input">
            </div>
          </div>
        

         
          <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-admin"  lay-submit lay-filter="LAY-user-back-search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
          </div>
        </div>
      </div>
<table class="layui-hide layui-table" id="seacherwxList" lay-filter="seacherwxList"></table>



<table class="layui-hide" id="wxList" lay-filter="wxList"></table>

<script type="text/html" id="barDemo">

    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>

</script>

<form class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">

    <div class="layui-form-item layui-form-text">

        <label class="layui-form-label">授权域名</label>
       <input type="hidden" name="gid" value="">
        <div class="layui-input-block">
        <textarea name="domain" placeholder="请输入授权，每个域名用回车分开，切记，切记~~~
        例如:
        www.a2bc.com
        bac.baidu.com
        qq.sogo.com
        " class="layui-textarea"></textarea>
        </div>

    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-wx-create-submit" id="LAY-wx-create-submit" value="确认">
    </div>
</form>
<div class="layui-carousel layadmin-carousel layadmin-dataview tishi" data-anim="fade" lay-filter="LAY-index-dataview">
        <li>1、只需要添加域名即可， 不包含http 或者 https  和链接后缀，例如：http://wxcopy.trj.com/ad/index.html,只需要添加：wxcopy.trj.com </li>
        <li>2、如果有多个链接在一个域名下面。只需要绑定一次就可以。不需要多次绑定授权。</li>
        <li>3、有什么问题及时联系技术人员。</li>
    <!--     <li>4、已绑定域名停用后记得删除</li> -->
        <!-- <li>5、账户到期时间为：2023-05-20</li>
        <li>6、可授权域名为：30个</li> -->
    </div>
    

<script src="__STATIC__/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table','upload'], function(){
        var $ = layui.$
            ,form = layui.form
            ,table = layui.table;



        //监听提交
        form.on('submit(demo1)', function(data){
            console.log(data.field);
            $.ajax({
                url:"addDomain",
                type:"POST",
                dataType:"json",
                data:data.field,
                success:function (res) {
                    console.log(res);
                    if (res.code == 1 ){
                        layer.msg(res['msg'],{icon: 1,time: 1000 },function () {
                            $("#layuiadmin-form-admin")[0].reset();
                            // $('#img').attr('src', '');
                            layui.form.render();
                            table.reload('wxList');

                        });
                    }
                }
            });

            return false;
        });

        // //监听搜索
        form.on('submit(LAY-user-back-search)', function(data){
        var domain = data.field;
        console.log(domain);
                table.render({
                    elem: '#seacherwxList'
                    ,url:'seacherDomainList'
                    ,method:"post"
                    ,where:domain
                    // ,toolbar: '#barDemo' //开启头部工具栏，并为其绑定左侧模板
                    ,title: '搜索授权域名列表'
                    ,cols: [[
                        { title:'ID', fixed: 'left', type:'numbers'}
                        // ,{field:'id', type:'checkbox'}
                        ,{field:'domain', title:'搜索授权域名列表',sort:true}
                        ,{fixed:'right', title:'操作', toolbar: '#barDemo'}
                    ]]
                    
                });
                
        });


        //获取添加后的授权域名
        table.render({
            elem: '#wxList'
            ,url:'domainList'
            ,method:"post"
            // ,toolbar: '#barDemo' //开启头部工具栏，并为其绑定左侧模板
            ,title: '微信列表'
            ,cols: [[
                 { title:'ID', fixed: 'left', type:'numbers'}
                // ,{field:'id', type:'checkbox'}
                ,{field:'domain', title:'授权域名',sort:true,}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
            ]]
            , done: function (res, curr, count) {
                $('th').css({'background-color': 'blue', 'color': '#fff'});
            }

            // 排序（倒序）输出
            ,initSort:{
                field:'id'
                ,type:'desc'
            }
            ,page: true
            ,limits: [15,20,30]  //一页选择显示3,5或10条数据
            ,limit:15
             // 解决layui分页数据不变的情况
            // https://blog.csdn.net/qq_35077107/article/details/101168088
            ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据，res为从url中get到的数据
                        var result;
                        console.log(this);
                        console.log(JSON.stringify(res));
                        if(this.page.curr){
                            result = res.data.slice(this.limit*(this.page.curr-1),this.limit*this.page.curr);
                        }
                        else{
                            result=res.data.slice(0,this.limit);
                        }
                        return {
                            "code": res.code, //解析接口状态
                            "msg": res.msg, //解析提示文本
                            "count": res.count, //解析数据长度
                            "data": result //解析数据列表
                        };
                    }
             // 解决layui分页数据不变的情况

            
        });

        // table列表删除事件
        table.on('tool(wxList)', function(obj){
            var data = obj.data;
            console.log(data);
            if(obj.event === 'del'){
                layer.msg('122');
                layer.confirm('确认删除该条授权域名吗？删除后该域名将无法获取数据！', function(index){

                    $.ajax({
                        type: "GET",
                        url:'deleteDomain',
                        data:data,
                        dataType:"json",
                        success:function (res) {
                            if (res['code']==1){
                                layer.msg(res['msg'],{icon: 1,time: 1000 },function () {
                                    obj.del();
                                    layer.close(index);
                                    table.reload('wxList');
                                    
                                });
                            }else {
                                layer.msg(res['msg'],{icon: 2,time: 1000 });
                            }
                        }
                    });
                });
            };
            
        });

         // {搜索}列表删除事件
         table.on('tool(seacherwxList)', function(obj){
            var data = obj.data;
            console.log(data);
            if(obj.event === 'del'){
                layer.msg('122');
                layer.confirm('确认删除该条授权域名吗？删除后该域名将无法获取数据！', function(index){
                    $.ajax({
                        type: "GET",
                        url:'deleteDomain',
                        data:data,
                        dataType:"json",
                        success:function (res) {
                            if (res['code']==1){
                                layer.msg(res['msg'],{icon: 1,time: 1000 },function () {
                                    obj.del();
                                    layer.close(index);
                                    table.reload('seacherwxList');
                                    table.reload('wxList');
                                    
                                });
                            }else {
                                layer.msg(res['msg'],{icon: 2,time: 1000 });
                            }
                        }
                    });
                });
            }
        });

    });
</script>
</body>
</html>

